package com.ysh.mybatis.mapper;

import com.ysh.mybatis.pojo.TbUser;
import com.ysh.mybatis.pojo.TbUserDto;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 袁胜虎 on 2022/8/25 19:43
 */
public interface UserMapper {
    @Select("select * from tb_user where id = #{id}")
    TbUser findById(Long id);

    @Select("select * from tb_user where username = #{username} and password = #{password}")
    TbUser findByUserNameAndPassword(@Param("username")String username,@Param("password")String password);
    @Select("select * from tb_user where username = #{username} and password = #{password}")
    TbUser findByUserNameAndPasswordMap( Map paramMap);
    @Select("select * from tb_user where username = #{map.username} and password = #{map.password}")
    TbUser findByUserNameAndPasswordMap2(@Param("map") Map paramMap);
    @Select("select * from tb_user where username = #{username} and password = #{password}")
    TbUser findUserNameAndPasswordPojo(TbUserDto tbUserDto);
    @Select("select * from tb_user where email like concat('%',#{email},'%')")
    List<TbUser> findByIdEmailKiKe(String email);
    @Select("select * from tb_user")
    List<TbUser> findAll();

    @Delete("delete from tb_user where id = #{id}")
    int deleteById(Long id);
    @Insert("INSERT INTO tb_user(username, password, email, gender) VALUES (#{username},#{password},#{email},#{gender})")
    void addUser(TbUser tbUser);
    @SelectKey(keyProperty = "id",keyColumn = "id",resultType = Long.class,statement = "select last_insert_id()",before = false)
    @Insert("insert into tb_user (username, password, email, gender)values(#{username}, #{password}, #{email}, #{gender})")
    void addUserAndGetId(TbUser tbUser);
}
